package com.hzhc.controller.sysmanage;

import com.hzhc.common.BaseController;
import com.hzhc.dto.RouterDto;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.SysYzsMenuService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.utils.TokenUtil;
import com.hzhc.vo.SysMenuVo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Objects;

/**
 * 菜单管理
 *
 * @author 功不唐捐
 * @since 2024-03-11
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/system/menu")
public class SysYzsMenuController extends BaseController {

	private final SysYzsMenuService yzsMenuService;

	/**
	 * 获取路由信息
	 *
	 * @return 路由信息
	 */
	@PostMapping("getRouters")
	public ResultUtil< List<RouterDto>> getRouters(HttpServletRequest request){
		Long memberId = Objects.requireNonNull(TokenUtil.getUserMember(request)).getId();//memberId
		List<SysMenuVo> menus = yzsMenuService.selectMenuTreeByMemberId(memberId);
		return ResultUtil.build(yzsMenuService.buildMenus(menus), ResultUtilCodeEnum.SUCCESS);
	}
}
